<?php
/**
 * Created by PhpStorm.
 * User: shichen
 * Date: 2018/11/1
 * Time: 14:48
 */

namespace app\admin\controller;


use think\Controller;
use think\Request;
class Admin extends Controller
{
    public function _initialize()
    {

        //判断session是否存在
        if(!session('?user')){
            //跳转到 登陆页
            $this->redirect(url('admin/Index/index'));
        }

        $mname = Request::instance()->controller();
        $mname=strtolower($mname);

        $aname = Request::instance()->action();
        $aname=strtolower($aname);

        $grant = session('nodelist');

        $name = session('user')['username'];

        if ($name != 'admin1')
        {
            //验证操作权限



            if(empty($grant[$mname]) || !in_array($aname,$grant[$mname])){

                $this->error("抱歉！没有操作权限！");
            }
        }

    }

}